﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Vibz.TeamAssignment.Common.Entity;

namespace Vibz.TeamAssignment
{
    internal partial class AssignmentHistory :Form
    {
        AssignmentClient _aClient;
        int _taskId;
        public AssignmentHistory(AssignmentClient client, int taskId)
        {
            InitializeComponent();
            _aClient = client;
            _taskId = taskId;
            LoadTaskFlow();
        }
        void LoadTaskFlow()
        {
            List<TaskAssignment> tAssList= _aClient.GetAllAssignments(_taskId);
            foreach(TaskAssignment tAss in tAssList)
            {
                string nodeText = "";
                switch(tAss.AssignStatus)
                {
                    case AssignStatus.Assigned:
                        string assText = tAss.IsRequest ? "Request" : "Assign";

                        nodeText = assText + "ed by " + tAss.AssignBy
                            + " to " + tAss.AssignedTo + " on " + tAss.AssignRequestDate.ToShortDateString();
                        break;
                    case AssignStatus.Accepted:
                        nodeText = "Accepted by " + tAss.AssignBy
                            + " on " + tAss.AssignRequestDate.ToShortDateString();
                        break;
                    case AssignStatus.Rejected:
                        nodeText = "Rejected by " + tAss.AssignBy
                            + " and assigned back to " + tAss.AssignedTo + " on " + tAss.AssignRequestDate.ToShortDateString();
                        break;
                    case AssignStatus.Closed:
                        nodeText = "Closed by " + tAss.AssignBy
                            + " on " + tAss.AssignRequestDate.ToShortDateString();
                        break;
                }
                string comment = _aClient.RevertRTF(tAss.AssignComment);
                if(string.IsNullOrEmpty(comment))
                    comment = "No comment.";
                tvHistory.Nodes.Add(new TreeNode(nodeText, new TreeNode[]
                    {
                        new TreeNode(comment)
                    }));
            }
        }
    }
}
